<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
  <el-page-header style="background-color: gold;color: black" @back="goBack" content="详情页面" >
  </el-page-header>
    <el-upload
            limit="1"
            name="pic"
            action="/upload"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-success="handlerSuccess"
            :on-remove="handleRemove">
        <i class="el-icon-plus"></i>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
    <el-button @click="insert()">上传</el-button>

</div>
</body>
<!--引入Axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
   let v = new Vue({
        el: '#app',
        data: function() {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                url:""
            }
        },
     methods: {
         handlerSuccess(response,file,fileList){
             v.url=response
         },
       goBack() {
         console.log('go back');
         history.back();
       },
         handleRemove(file, fileList) {
             console.log(file, fileList);
         },
         handlePictureCardPreview(file) {
             this.dialogImageUrl = file.url;
             this.dialogVisible = true;
         },
         insert(){
             if(v.url==""){
                 v.$message.error("请选择上传的图片!")
                 return;
             }
        axios.get("/banner/insert?url="+v.url).then(function () {
            location.href="/admin.html"
        })
         }
     }
    })
</script>
</html>